<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>俱乐部信息列表</title>
    <script src="../../scripts/boot.js" type="text/javascript"></script>
    <script src="../../demo/demo.css" type="text/javascript"></script>
    <style type="text/css">
      html,
      body {
        margin: 0;
        padding: 0;
        border: 0;
        width: 100%;
        height: 100%;
        overflow: hidden;
      }
    </style>
  </head>
  <body>
    <div style="width: 100%">
      <div class="mini-toolbar" style="border-bottom: 0; padding: 0px">
        <table style="width: 100%">
          <tr>
            <td style="width: 100%">
              <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
              <a class="mini-button" iconCls="icon-remove" onclick="remove()"
                >删除</a
              >
            </td>
            <td style="white-space: nowrap">
              <input
                id="idClubName"
                class="mini-textbox"
                emptyText="请输入俱乐部名称"
                style="width: 150px"
                onenter="onKeyEnter"
              />
              <input
                id="idClubType"
                class="mini-combobox"
                url="../../data/club.txt"
                emptyText="请选择俱乐部类型"
                style="width: 150px"
                onenter="onKeyEnter"
              />
              <a class="mini-button" iconCls="icon-find" onclick="search()"
                >查询</a
              >
              <a class="mini-button" iconCls="icon-reload" onclick="clear()"
                >清空</a
              >
            </td>
          </tr>
        </table>
      </div>
    </div>
    <!--撑满页面-->
    <div class="mini-fit">
      <div
        id="datagrid1"
        class="mini-datagrid"
        style="width: 100%; height: 100%"
        url="/club/clublistaction?method=queryClubInfo"
        idField="activityId"
        multiSelect="true"
      >
        <div property="columns">
          <div name="clubId"></div>
          <div type="checkcolumn"></div>
          <div type="indexcolumn">序号</div>
          <div field="clubName" width="120" headerAlign="center" align="center">
            俱乐部名称
          </div>
          <div field="head" width="120" headerAlign="center" align="center">
            负责人
          </div>
          <div
            field="clubType"
            width="120"
            headerAlign="center"
            align="center"
            renderer="onClubRenderer"
          >
            俱乐部类型
          </div>
          <div
            field="createTime"
            width="120"
            headerAlign="center"
            align="center"
          >
            创建时间
          </div>
          <div
            field="activityNum"
            width="60"
            headerAlign="center"
            align="center"
          >
            活动次数
          </div>
          <div field="remain" width="60" headerAlign="center" align="center">
            余票数量
          </div>
          <div
            field="optionButton"
            width="80"
            headerAlign="center"
            align="center"
            renderer="onOptionRenderer"
          >
            操作
          </div>
        </div>
      </div>
    </div>

    <script type="text/javascript">
      mini.parse();

      var grid = mini.get("datagrid1");
      grid.load();
      grid.hideColumn("clubId");
      // grid.sortBy("createtime", "desc");

      var clubRender = null;
      // 获取地区映射
      clubReflect();

      ////////////////控件渲染//////////////////
      function onOptionRenderer(e) {
        return (
          '<a class="mini-button" onclick="edit(\'' +
          e.row.clubId +
          "')\">&nbsp;&nbsp;编辑&nbsp;&nbsp;</a> &nbsp;" +
          '<a class="mini-button " onclick="deleteInfo(\'' +
          e.row.clubId +
          "')\">&nbsp;&nbsp;删除&nbsp;&nbsp;</a> &nbsp;"
        );
      }

      // 渲染俱乐部类型
      function onClubRenderer(e) {
        for (var i = 0, l = clubRender.length; i < l; i++) {
          var g = clubRender[i];
          if (g.id == e.value) return g.text;
        }
        return "";
      }

      //////////////////按钮//////////////////////

      // 删除
      function remove() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
          var ids = [];
          for (var i = 0, l = rows.length; i < l; i++) {
            ids.push(rows[i].clubId);
          }
          var id = ids.join(",");
          mini.confirm("确定删除选中记录？", "提示", function (action) {
            if (action == "ok") {
              deleteClubAjax(id)
            }
          });
        } else {
          alert("请选中一条记录");
        }
      }

      // 单个级联删除
      function deleteInfo(clubId) {
        mini.confirm("确定删除选中记录？", "提示", function (action) {
          if (action == "ok") {
            deleteClubAjax(clubId)
          }
        });
      }

      // 搜索
      function search() {
        var clubName = mini.get("idClubName").getValue();
        var clubType = mini.get("idClubType").getValue();
        grid.load({ clubName: clubName, clubType, clubType });
      }

      // enter搜索
      function onKeyEnter(e) {
        search();
      }

      function clear() {
        mini.get("idClubName").setValue(null);
        mini.get("idClubType").setValue(null);
        search();
      }

      ////////////////ajax/////////////////////////
      // 获取地区映射
      function clubReflect() {
        $.ajax({
          url: bootPATH + "../data/club.txt",
          type: "GET",
          cache: false,
          success: function (text) {
            // 一定要转一下不然不是对象形式
            clubRender = mini.decode(text);
          },
          error: function () {},
        });
      }

      // 级联删除接口
      function deleteClubAjax(clubIds) {
        $.ajax({
          url: "/club/clubeditaction?method=deleteClubinfo&clubIds=" + clubIds,
          success: function (text) {
            mini.alert(text, "提示", function () {
              grid.reload();
            });
          },
          error: function () {},
        });
      }

      /////////////////新增页///////////////////////////
      function add() {
        mini.open({
          url: bootPATH + "../pages/clubinfo/clubadd.html",
          title: "新增俱乐部",
          width: 600,
          height: 400,
          onload: function () {
            // var iframe = this.getIFrameEl();
            // var data = { action: "new" };
            // iframe.contentWindow.SetData(data);
          },
          ondestroy: function (action) {
            grid.reload();
          },
        });
      }

      function edit(clubId) {
        mini.open({
          url: bootPATH + "../pages/clubinfo/clubedit.html",
          title: "修改俱乐部",
          width: 600,
          height: 400,
          onload: function () {
            var iframe = this.getIFrameEl();
            var data = { clubId: clubId };
            iframe.contentWindow.SetData(data);
          },
          ondestroy: function (action) {
            grid.reload();
          },
        });
      }
    </script>
  </body>
</html>
